package blue.qingyu.whimurmur.lookBack;

import com.jfinal.plugin.activerecord.Db;
import io.jpress.core.addon.Addon;
import io.jpress.core.addon.AddonInfo;

/**
 * 这是一个 JPress 插件的 hello world 项目，没有具体的功能。
 *
 * 其存在的目的是为了帮助开发者，通过 hello world ，了解如何开发一个 JPress 插件
 *
 */
public class LookBackAddon implements Addon {

    @Override
    public void onInstall(AddonInfo addonInfo) {

        // 只建表不删表
        String createSql = "CREATE TABLE IF NOT EXISTS `ex_trace_header` ( " + 
        		"	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', " + 
        		"	`title` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '标题' COLLATE 'utf8mb4_general_ci', " + 
        		"	`date` DATE NOT NULL, " + 
        		"	`created` DATETIME NOT NULL, " + 
        		"	`created_by` VARCHAR(128) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci', " +
        		"	PRIMARY KEY (`id`) USING BTREE " + 
        		") " + 
        		"COLLATE='utf8mb4_general_ci' " + 
        		"ENGINE=InnoDB";
        String createSql2 = "CREATE TABLE IF NOT EXISTS `ex_trace_line` ( " + 
        		"	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', " + 
        		"	`trace_header_id` INT(10) UNSIGNED NOT NULL COMMENT '头表id', " + 
        		"	`content` VARCHAR(2048) NOT NULL DEFAULT '' COMMENT '内容' COLLATE 'utf8mb4_general_ci', " + 
        		"	`image` VARCHAR(2048) NOT NULL DEFAULT '' COMMENT '图片' COLLATE 'utf8mb4_general_ci', " + 
        		"	PRIMARY KEY (`id`) USING BTREE " + 
        		") " + 
        		"COLLATE='utf8mb4_general_ci'";
        Db.update(createSql);
        Db.update(createSql2);
        // 安装页面资源文件

    }

    @Override
    public void onUninstall(AddonInfo addonInfo) {
        // 删除页面资源文件

    }

    @Override
    public void onStart(AddonInfo addonInfo) {

    }

    @Override
    public void onStop(AddonInfo addonInfo) {


    }
}
